package com.yycx.module.system.provider.service.impl;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.common.mybatis.query.CriteriaSave;
import com.yycx.common.utils.DateUtil;
import com.yycx.module.system.client.entity.SysOperationLog;
import com.yycx.module.system.provider.mapper.SysOperationLogMapper;
import com.yycx.module.system.provider.service.SysOperationLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 操作日志表接口实现类
 *
 * @author flyme
 * @date 2024-08-27
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysOperationLogServiceImpl extends BaseServiceImpl<SysOperationLogMapper, SysOperationLog> implements SysOperationLogService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, SysOperationLog sol, EntityMap extra) {
        sol.setUpdateTime(DateUtil.now());
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<SysOperationLog> cq, SysOperationLog sol, EntityMap requestMap) {
        cq.orderByDesc("sol.updateTime","sol.createTime");
        cq.like("sol.bizId", sol.getBizId());
        return ResultBody.ok();
    }
    @Override
    public SysOperationLog findByBusId(String busId) {
        CriteriaQuery cq = new CriteriaQuery(SysOperationLog.class);
        cq.eq("bizId", busId);
        return getOne(cq);
    }

    @Override
    public ResultBody addLog(Long bizId,String bizType,String content){
        SysOperationLog sysOperationLog = new SysOperationLog();
        sysOperationLog.setBizId(bizId.toString());
        sysOperationLog.setBizType(bizType);
        sysOperationLog.setMsg(content);

        save(sysOperationLog);
        return ResultBody.ok();
    }
}
